package main;

import java.awt.*;
import javax.swing.*;

public class Board extends JPanel implements Commons, Runnable{
	private static final long serialVersionUID = 1L;
	
	Player player;
	Alien aliens;
	Image backgroundImg;
	Image playerImg;
	private boolean ingame = true;
	Image alienImg;
	
	public Board() {
		player = new Player();
		aliens = new Alien(300, 200);
		
		try {
			backgroundImg = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("board.png"), "board.png"));
			playerImg = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("player.png"), "player.png"));
			alienImg = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("alien.png"), "alien.png"));
		}
		catch (Exception e) {}
	}

	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g); 
		g.drawImage(backgroundImg, 0, 0, this.getWidth(), this.getHeight(), this);
		g.drawImage(playerImg, player.getX(), player.getY(), 30, 30, this);
		g.drawImage(alienImg, aliens.getX(), aliens.getY(), 30, 30, this);
	}
	
	public void animationCycle(){
		player.act();
	}
	
	public void run(){
		while(ingame){
			repaint();
			animationCycle();
			//SVN er homo
		}
	}
}